package ch.unisi.inf.pfii.teamwhite.risk.core;

import junit.framework.TestCase;
import ch.unisi.inf.pfii.teamwhite.risk.core.player.Human;
import ch.unisi.inf.pfii.teamwhite.risk.core.player.Player;

public class AttackHandlerTest extends TestCase {

	/**
	 * Tests to see if the attacker wins with the given amount of ships for both the Defender and the
	 * attacker.It will happen at least 67% of the time.	
	 */
	public void testIfAttackerWinsMostOfTheTime()
	{
		Player player1 = new Human("User");
		int attackingShips = 300;
		int defendingShips = 100;
		Planet planet = new Planet("Pluto", player1,5000);		
		AttackHandler ah = new AttackHandler();
		ah.handleAttack(player1, attackingShips, defendingShips, planet);
		assertEquals(true, Integer.parseInt(ah.getLost()) > Integer.parseInt(ah.getDestroyed()));
	}	
	
	/**
	 * Tests to see if the Defender wins with the given amount of ships for both the Defender and the
	 * attacker. It will happen at least 67% of the time.
	 */
	public void testIfDefenderWinsMostOfTheTime()
	{
		Player player1 = new Human("User");
		int attackingShips = 100;
		int defendingShips = 300;
		Planet planet = new Planet("Pluto", player1,5000);		
		AttackHandler ah = new AttackHandler();
		ah.handleAttack(player1, attackingShips, defendingShips, planet);
		assertEquals(true, Integer.parseInt(ah.getLost()) > Integer.parseInt(ah.getDestroyed()));
	}			
	
	/**
	 * Unusual test to see if the attacker(AI) wins against the defender(Human) if they have 
	 * the same number of ships. It will happen at least 50% of the time on a long run if the players have
	 * lot of ships
	 */
	public void testFairnessForStrongPlayers()
	{
		Player player1 = new Human("User");
		int attackingShips = 100;
		int defendingShips = 100;
		Planet planet = new Planet("Pluto", player1,5000);		
		AttackHandler ah = new AttackHandler();
		ah.handleAttack(player1, attackingShips, defendingShips, planet);
		assertEquals(true, Integer.parseInt(ah.getLost()) > Integer.parseInt(ah.getDestroyed()));
	}	
	
	/**
	 * tests if both the human and the AI having he same but only one ship at their disposal draw
	 */	
	public void testFairnessForWeakPlayers()
	{
		Player player1 = new Human("User");
		int attackingShips = 1;
		int defendingShips = 1;
		Planet planet = new Planet("Pluto", player1,5000);		
		AttackHandler ah = new AttackHandler();
		ah.handleAttack(player1, attackingShips, defendingShips, planet);
		assertEquals(true, Integer.parseInt(ah.getLost()) > Integer.parseInt(ah.getDestroyed()));
	}
	
}
